@extends('layouts.admin_iframe')
@section('content')
	<style>
		li{
			list-style: none;
		}
	</style>

<script>
	$(function(){
		//分类内容改变事件
		$(".fenlei").change(function(){
			cid = $(".fenlei").val();
			$.post("{{url('admin/get_attr/')}}",{'_token':'{{csrf_token()}}',"cid":cid},function(data){
				var attr="";
				var spec="";
				$.each(data,function(k,v){
//
//
					//如果是属性
					if(v.atype=="属性"){
						attr += '<tr class="active">';
						attr += '<td>'+v.aname+'</td>';
						attr +='<td>';
						attr +='<select name="attr['+v.aid+']" >';
						attr +='<option value="">请选择</option>';
						$.each(v.tavalue,function (kk,vv) {
							attr +='<option value="'+vv+'">'+vv+'</option>';
						});
						attr +='</select>';
						attr +='</td></tr>';
					}else{
						spec += '<tr class="active">';
						spec += '<td>'+v.aname+'</td>';
						spec +='<td>';
						spec +='<select name="spec['+v.aid+']" >';
						spec +='<option value="">请选择</option>';
						$.each(v.tavalue,function (kk,vv) {
							spec +='<option value="'+vv+'">'+vv+'</option>';
						});
						spec +='</select>';
						spec +='</td></tr>';
					}
//
				});

				$("#attr").html(attr);
				$("#spec").html(spec);

			});
		})
	})
</script>
<form action="{{url('admin/category')}}" method="post">
	{{csrf_field()}}
	<div class="alert alert-success">添加商品</div>
	<div class="form-group">
		<label for="exampleInputEmail1">商品名称</label>
		<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入商品名称" required="" name="gname">
	</div>

	<div class="form-group">
		<label for="exampleInputEmail1">商品描述</label>
		<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入商品描述" required="" name="goods_introduce">
	</div>

	<div class="form-group">
		<label for="exampleInputEmail1">所属分类</label>
		<select name="cate_cid" class="form-control fenlei">
			<option value="0">请选择</option>
			@foreach($cate_datas_tree as $v)
			<option value="{{$v->cid}}">{{$v->_cname}}</option>
			@endforeach
		</select>
	</div>

	<div class="form-group">
		<label for="exampleInputEmail1">单位</label>
		<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入单位" required="" name="unit">
	</div>

	<div class="form-group">
		<label for="exampleInputEmail1">库存</label>
		<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入分类名称" required="" name="gi">
	</div>

	<div class="form-group">
		<label for="exampleInputEmail1">市场价</label>
		<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入分类名称" required="" name="price">
	</div>

	<div class="form-group">
		<label for="exampleInputEmail1">商城价</label>
		<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入分类名称" required="" name="money">
	</div>

	<div class="form-group">
		<label for="exampleInputEmail1">货号</label>
		<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入分类名称" required="" name="gnum">
	</div>

	<div class="form-group">
		<label for="exampleInputEmail1">点击次数</label>
		<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入分类名称" required="" name="click">
	</div>


	<div class="alert alert-success">商品属性</div>
		<table id="attr" class="table table-hover">

		</table>

	<div class="alert alert-success">商品规格</div>
	<table id="spec" class="table table-hover">

	</table>
	{{--<div class="form-group">--}}
		{{--<label for="exampleInputEmail1">所属类型</label>--}}
		{{--<select name="type_tid" class="form-control">--}}
			{{--<option value="0">请选择</option>--}}
			{{--@foreach($type_datas as $v)--}}
			{{--<option value="{{$v->tid}}">{{$v->tname}}</option>--}}
			{{--@endforeach--}}
		{{--</select>--}}
	{{--</div>--}}
	{{--<div class="form-group">--}}
		{{--<label for="exampleInputEmail1">分类标题</label>--}}
		{{--<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入分类标题" required="" name="">--}}
	{{--</div>--}}
	{{--<div class="form-group">--}}
		{{--<label for="exampleInputEmail1">分类关键字</label>--}}
		{{--<textarea name="" rows="5" cols=""  class="form-control" placeholder="请输入分类关键字"></textarea>--}}
	{{--</div>--}}
	{{--<div class="form-group">--}}
		{{--<label for="exampleInputEmail1">分类描述</label>--}}
		{{--<textarea name="" rows="5" cols=""  class="form-control" placeholder="请输入分类描述"></textarea>--}}
	{{--</div>--}}
	<div class="alert alert-success shangchuan1">
		列表图
		<table id="tu1">
		<tr>
			<th>上传列表图：</th>
			<td >

				<input type="text" size="50" name="art_thumb">
				<input id="file_upload" name="file_upload" type="file" multiple="true">
				<script src="{{asset('resources/org/uploadify/jquery.uploadify.min.js')}}" type="text/javascript"></script>
				<link rel="stylesheet" type="text/css" href="{{asset('resources/org/uploadify/uploadify.css')}}">
				<script type="text/javascript">
					<?php $timestamp = time();?>
                    $(function() {
						$('#file_upload').uploadify({
							'buttonText' : '图片上传',
							'formData'     : {
								'timestamp' : '<?php echo $timestamp;?>',
								'_token'     : "{{csrf_token()}}"
							},
							'swf'      : "{{asset('resources/org/uploadify/uploadify.swf')}}",
							'uploader' : "{{url('admin/upload_set')}}",
							'onUploadSuccess' : function(file, data, response) {
								var html="<ul class='shanchu'><li>";
								html+="<input type='hidden' name='big_pics' value='/"+data+"'/><a path='/"+data+"' href='javascript:;' id='self-close'>X</a></li>";
								html+="<li><img width='600' height='400' src='/"+data+"'/>";
								html+="</li></ul>";
								$(".shangchuan1").append(html);
//								$("#upload_id").attr("src",'/'+data);//显示图片
								$("input[name=art_thumb]").val(data);//input中显示地址
							}
						});

						//删除图片
//						var i = 1;
						$('#self-close').live('click',function(){

							var path = $(this).attr('path');
							$.ajax({
								type:'post',
								url:"{{url('admin/delete_upload_pic')}}",
								data:{'_token':'{{csrf_token()}}','pic_name':path},
								//指定服务器返回的数据类型
								dataType:'',
								success:function(phpData){

								}
							});

							$(this).parents('.shanchu').remove();

						});

					});
				</script>
				<style>
					.uploadify{display:inline-block;}
					.uploadify-button{border:none; border-radius:5px; margin-top:8px;}
					table.add_tab tr td span.uploadify-button-text{color: #FFF; margin:0;}
				</style>

			</td>
		</tr>
		</table>
	</div>
	<div class="alert alert-success">商品详情描述</div>
	{{--//百度编辑器--}}
	<script type="text/javascript" charset="utf-8" src="{{asset('./resources/org/ueditor/ueditor.config.js')}}"></script>
	<script type="text/javascript" charset="utf-8" src="{{asset('./resources/org/ueditor/ueditor.all.min.js')}}"> </script>
	<script type="text/javascript" charset="utf-8" src="{{asset('./resources/org/ueditor/lang/zh-cn/zh-cn.js')}}"></script>
	<div>
		<script id="editor" type="text/plain" style="width:100%;height:500px;" name="content"></script>
		<script>
			var ue = UE.getEditor('editor');
		</script>
	</div>
	<div class="form-group">
		<label for="exampleInputEmail1">分类排序</label>
		<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入分类排序" required="" name="sort" value="100">
	</div>


	<button class="btn btn-primary btn-block" type="submit"> 确定 </button>
</form>
@endsection